/*    */ package provider;
/*    */ 
/*    */ import java.io.File;
/*    */ import java.io.FileInputStream;
/*    */ import java.io.FileNotFoundException;
/*    */ import java.io.IOException;
/*    */ import org.apache.logging.log4j.LogManager;
/*    */ import org.apache.logging.log4j.Logger;
/*    */ 
/*    */ 
/*    */ public class MapleDataProvider
/*    */ {
/* 13 */   private static final Logger log = LogManager.getLogger();
/*    */   private final File root;
/*    */   private final MapleDataDirectoryEntry rootForNavigation;
/*    */   
/*    */   public MapleDataProvider(File fileIn) {
/* 18 */     this.root = fileIn;
/* 19 */     this.rootForNavigation = new MapleDataDirectoryEntry(fileIn.getName(), 0, 0, null);
/* 20 */     fillMapleDataEntitys(this.root, this.rootForNavigation);
/*    */   }
/*    */   
/*    */   private void fillMapleDataEntitys(File lroot, MapleDataDirectoryEntry wzdir) {
/* 24 */     for (File file : lroot.listFiles()) {
/* 25 */       String fileName = file.getName();
/* 26 */       if (file.isDirectory() && !fileName.endsWith(".img")) {
/* 27 */         MapleDataDirectoryEntry newDir = new MapleDataDirectoryEntry(fileName, 0, 0, wzdir);
/* 28 */         wzdir.addDirectory(newDir);
/* 29 */         fillMapleDataEntitys(file, newDir);
/* 30 */       } else if (fileName.endsWith(".xml")) {
/* 31 */         wzdir.addFile(new MapleDataFileEntry(fileName.substring(0, fileName.length() - 4), 0, 0, wzdir));
/*    */       } 
/*    */     } 
/*    */   } public MapleData getData(String path) {
/*    */     FileInputStream fis;
/*    */     MapleData domMapleData;
/* 37 */     File dataFile = new File(this.root, path + ".xml");
/* 38 */     File imageDataDir = new File(this.root, path);
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */     
/* 44 */     if (!dataFile.exists()) {
/* 45 */       return null;
/*    */     }
/*    */     
/*    */     try {
/* 49 */       fis = new FileInputStream(dataFile);
/* 50 */     } catch (FileNotFoundException e) {
/* 51 */       log.error("Datafile " + path + " does not exist in " + this.root.getAbsolutePath(), e);
/* 52 */       throw new RuntimeException("Datafile " + path + " does not exist in " + this.root.getAbsolutePath());
/*    */     } 
/*    */     
/*    */     try {
/* 56 */       domMapleData = new MapleData(fis, imageDataDir.getParentFile());
/*    */     } finally {
/*    */       try {
/* 59 */         fis.close();
/* 60 */       } catch (IOException e) {
/* 61 */         throw new RuntimeException(e);
/*    */       } 
/*    */     } 
/* 64 */     return domMapleData;
/*    */   } public MapleData getReturnData(String path) {
/*    */     FileInputStream fis;
/*    */     MapleData domMapleData;
/* 68 */     File dataFile = new File(this.root, path + ".xml");
/* 69 */     File imageDataDir = new File(this.root, path);
/*    */ 
/*    */     
/*    */     try {
/* 73 */       fis = new FileInputStream(dataFile);
/* 74 */     } catch (FileNotFoundException e) {
/* 75 */       return null;
/*    */     } 
/*    */     
/*    */     try {
/* 79 */       domMapleData = new MapleData(fis, imageDataDir.getParentFile());
/*    */     } finally {
/*    */       try {
/* 82 */         fis.close();
/* 83 */       } catch (IOException e) {
/* 84 */         throw new RuntimeException(e);
/*    */       } 
/*    */     } 
/* 87 */     return domMapleData;
/*    */   }
/*    */   
/*    */   public MapleDataDirectoryEntry getRoot() {
/* 91 */     return this.rootForNavigation;
/*    */   }
/*    */ }


/* Location:              C:\PGX\Server.jar!\provider\MapleDataProvider.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */